<?require_once $_SERVER["DOCUMENT_ROOT"]."/system/core/prolog.php"?>
<?SetTitle("Админка::Элементы каталога");
	IncludeModule("catalog");
?>
<?switch ($_GET["ACTION"]):
	case 'ADD_SECTION':?>
		<h3><?=LANG("MODULE_CATALOG_SECTION_ADD_TITLE")?></h3>
		<?ShowMsg()?>
		<?Component::getComponent("catalog.section.add",
			"",
			Array(
				"FIELDS" => Array(
					"ID",
					"ACTIVE",
					"NAME",
					"CATALOG_SECTION_ID",
					"CATALOG_ID",
					"SORT",
					"CODE",
					"PREVIEW_PICTURE",
					"PREVIEW_TEXT",
					"PREVIEW_TEXT_TYPE",
					"DETAIL_PICTURE",
					"DETAIL_TEXT",
					"DETAIL_TEXT_TYPE",
				),
				"TYPE" => $_GET["TYPE"],
				"CATALOG_ID" => $_GET['CATALOG_ID'],
			)
		);?>
		<?break;
	case 'ADD':?>
		<h3><?=LANG("MODULE_CATALOG_ELEMENTS_ADD_TITLE")?></h3>
		<?ShowMsg()?>
		<?Component::getComponent("catalog.element.add",
			"",
			Array(
				"FIELDS" => Array(
					"ID",
					"ACTIVE",
					"NAME",
					"CATALOG_SECTION_ID",
					"CATALOG_ID",
					"SORT",
					"CODE",
					"PREVIEW_PICTURE",
					"PREVIEW_TEXT",
					"PREVIEW_TEXT_TYPE",
					"DETAIL_PICTURE",
					"DETAIL_TEXT",
					"DETAIL_TEXT_TYPE",
					"TAGS"
				),
				"TYPE" => $_GET["TYPE"],
				"CATALOG_ID" => $_GET['CATALOG_ID'],
			)
		);?>
	<?break?>
	<?case 'EDIT':?>
		<h3><?=LANG("MODULE_CATALOG_ELEMENTS_EDIT_TITLE")?></h3>
		<?ShowMsg()?>
		<?Component::getComponent("catalog.element.add",
			"",
			Array(
				"FIELDS" => Array(
					"ID",
					"ACTIVE",
					"NAME",
					"CATALOG_SECTION_ID",
					"CATALOG_ID",
					"SORT",
					"CODE",
					"PREVIEW_PICTURE",
					"PREVIEW_TEXT",
					"PREVIEW_TEXT_TYPE",
					"DETAIL_PICTURE",
					"DETAIL_TEXT",
					"DETAIL_TEXT_TYPE",
					"TAGS"
				),
				"ID" => $_GET['ID'],
				"CATALOG_ID" => $_GET['CATALOG_ID'],
				"TYPE" => $_GET["TYPE"]
			)
		);?>
	<?break?>
	<?case 'DELETE':?>
		<?ShowMsg()?>
		<?
			if(CatalogElement::Delete($_GET["ID"])) {
				AddMsg("Элемент успешно удалён");
				RedirectTo('/system/admin/catalog/');
			} else {
				echo ShowError("Ошибка при удалении элемента каталога");
			}
		?>
		<p><a href="/system/system/admin/catalog/">Список типов</a></p>
	<?break?>
		
	<?default:?>
		
	<?$arCaralogType = CatalogType::GetByID($_GET["TYPE"]);?>
	<h3><?=str_replace('#TYPE#', $arCaralogType["NAME"], LANG("MODULE_CATALOG_TITLE"))?></h3>
	<?ShowMsg()?>
	<p>
		<a href="?ACTION=ADD&TYPE=<?=sXss($_GET['TYPE'])?>&CATALOG_ID=<?=sXss($_GET['CATALOG_ID'])?>"><?=LANG("MODULE_CATALOG_ELEMENTS_ADD_TEXT")?></a>&nbsp;&nbsp;&nbsp;
		<a href="?ACTION=ADD_SECTION&TYPE=<?=sXss($_GET['TYPE'])?>&CATALOG_ID=<?=sXss($_GET['CATALOG_ID'])?>"><?=LANG("MODULE_CATALOG_SECTION_ADD_TEXT")?></a>
	</p>
	<?Component::getComponent("catalog.section.list",
		"admin",
		Array(
			"SECTION_ID" => $_GET["SECTION_ID"],
			"CATALOG_ID" => $_GET["CATALOG_ID"],
			"=CATALOG_TYPE" => $_GET["TYPE"],
		)
	);?>
	<?Component::getComponent("catalog.section",
		"admin",
		Array(
			"CATALOG_TYPE" => $_GET["TYPE"],
			"CATALOG_ID" => intVal($_GET["CATALOG_ID"]),
			"=SECTION_ID" => $_GET["SECTION_ID"]
		)
	);?>
	<?break;?>
<?endswitch?>

<p>
	<a href="/system/admin/catalog/">Список типов</a>&nbsp;&nbsp;
	<a href="/system/admin/catalog/catalog.php?TYPE=<?=$_GET["TYPE"]?>">Список каталогов</a>
</p>

<?require_once $_SERVER["DOCUMENT_ROOT"]."/system/core/epilog.php"?>